#include <iostream>
#include <unordered_map>
#include <map>
using namespace std;
int main()
{
	unordered_map<string, map<string,int>> mp;
	int n;
	cin >> n;
	int ret = 0;
	for (int i = 1;i <= n;i++)
	{
		string s, q;
		cin >> s >> q;
		s = s.substr(0, 2);
		if (s == q)continue;
		mp[s][q]++;
		ret += mp[q][s];
	}
	cout << ret<<endl;
	return 0;
}